/**
 * @description 两个栈 - 一个队列
 * @author 李子一
 */

export class Queue {
	private stack1: any[]
	private stack2: any[]

	constructor() {
		this.stack1 = []
		this.stack2 = []
	}

	add(elm: any) {
		this.stack1.push(elm)
	}

	delete() {
		const stack1 = this.stack1
		const stack2 = this.stack2

		if (stack2.length) {
			return stack2.pop()
		} else {
			while (stack1.length) {
				stack2.push(stack1.pop())
			}
			return stack2.pop()
		}
	}

	get length() {
		return this.stack1.length + this.stack2.length
	}
}

// 功能测试
const q = new Queue()
// q.add(100)
// q.add(200)
// q.add(300)
console.info(q.length)
console.info(q.delete())
console.info(q.length)
console.info(q.delete())
console.info(q.length)
